package zoo;


import org.apache.zookeeper.*;
import org.apache.zookeeper.data.Stat;

import java.io.IOException;

/**
 * @author CKC
 * @date 2022/11/15 18:14
 */
public class ZookeeperApplication {
    public static void main(String[] args) throws IOException, InterruptedException, KeeperException {
        ZooKeeper zooKeeper = new ZooKeeper("192.168.3.55:2181", 2000, new Watcher() {
            @Override
            public void process(WatchedEvent event) {
                System.out.println("---------");
            }
        });

        //创建
        String s = zooKeeper.create("/ckc", "ChenKeChen".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE , CreateMode.PERSISTENT);
        System.out.println(s);

        //    监听子节点变化
        zooKeeper.getChildren("/", true).forEach(System.out::println);

        // 判断子节点是否存在
        Stat exists = zooKeeper.exists("/ckc", false);
        System.out.println(exists);

    }
}
